package com.spzx.payment.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.RequiresLogin;
import com.spzx.payment.config.AlipayConfig;
import com.spzx.payment.service.IAlipayService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Package: com.spzx.payment.controller
 *
 * @author xiongkunYang
 * @description:
 * @since 2025/6/9 14:18
 */
@Slf4j
@Controller
@RequestMapping("/alipay")
@RequiredArgsConstructor
public class AlipayController extends BaseController {

    private final IAlipayService alipayService;

    @Operation(summary = "支付宝下单")
    @RequiresLogin
    @RequestMapping("submitAlipay/{orderNo}")
    @ResponseBody
    public AjaxResult submitAlipay(@PathVariable(value = "orderNo") String orderNo) {
        String form = alipayService.submitAlipay(orderNo);
        return success(form);
    }

    /**
     * 支付宝同步回调
     * @return 跳转页面
     */
    @Operation(summary = "支付宝同步回调")
    @GetMapping("callback/return")
    public String callBack() {
        // 同步回调给用户展示信息
        return "redirect:" + AlipayConfig.returnOrderUrl;
    }

    @Operation(summary = "支付宝异步回调")
    @RequestMapping("callback/notify")
    @ResponseBody
    public String alipayNotify(@RequestParam Map<String, String> paramMap) {
        log.info("AlipayController...alipayNotify方法执行了...");
        this.alipayService.alipayNotify(paramMap);
        return "success" ;
    }

}